<template>
  <div class="rank" ref="rank">
    <scroll :data="topList" class="topList" ref="topList">
      <ul>
        <li class="item" v-for="(item,index) in topList" :key="index" @click="selectItem(item)">
          <div class="icon">
            <img width="100" height="100" v-lazy="item.picUrl">
          </div>
          <ul class="songList">
            <li class="song" v-for="(song,index) in item.songList" :key="index">
              <span>{{index+1}}</span>
              <span>{{song.songname}}-{{song.singername}}</span>
            </li>
          </ul>
        </li>
      </ul>
    </scroll>
    <router-view></router-view>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getTopList} from 'api/rank'
  import {mixinPlayList} from 'common/js/mixin'
  import Scroll from 'base/scroll/scroll'
  import {mapMutations} from 'vuex'

  export default {
    mixins: [mixinPlayList],
    data () {
      return {
        topList: []
      }
    },
    created () {
      this._getTopList()
    },
    methods: {
      // 跳转进入排行榜详情歌曲界面
      selectItem (item) {
        this.$router.push({
          path: `/rank/${item.id}`
        })
        this.setTopList(item)
      },
      // 处理mini播发器出现时本页的bottom问题
      handlePlayList (playlist) {
        const bottom = playlist.length > 0 ? '60px' : ''
        this.$refs.rank.style.bottom = bottom
        this.$refs.topList.refresh()
      },
      // 获取推荐详情歌单数据
      _getTopList () {
        getTopList().then(res => {
          this.topList = res.data.topList
        })
      },
      ...mapMutations({
        setTopList: 'SET_TOP_LIST'
      })
    },
    components: {
      Scroll
    }
  }
</script>

<style scoped lang="stylus">
  @import "~common/stylus/variable.styl"
  @import "~common/stylus/mixin.styl"
  .rank
    position: fixed
    width: 100%
    top: 88px
    bottom: 0

    .topList
      height: 100%
      overflow: hidden

      .item
        display: flex
        margin: 0 20px
        padding-top: 20px
        height: 100px

        .icon
          flex: 0 0 100px
          width: 100px
          height: 100px

        .songList
          flex: 1
          display: flex
          flex-direction: column
          justify-content: center
          padding: 0 20px
          height: 100px
          overflow: hidden
          background: $color-highlight-background
          color: $color-text-d
          font-size: $font-size-small

          .song
            no-wrap()
            line-height: 26px
</style>
